﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
using DataProcessing;
namespace Gene
{
    /// <summary>
    /// ChooseSpecies.xaml 的交互逻辑
    /// </summary>
    public partial class ChooseSpeciesWindow : Window
    {
        public ChooseSpeciesWindow()
        {
            InitializeComponent();
        }

        bool _showVisiblityChoose = true;
        public void DisableVisibilityChoose()
        {
            _showVisiblityChoose = false;
        }
        string _customAnnotationFile = null;
        private void buttonLoadAnnotation_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            bool? ret = ofd.ShowDialog(this);
            if (ret.Value)
            {
                _customAnnotationFile = ofd.FileName;
                
            }
        }

        private void buttonOK_Click(object sender, RoutedEventArgs e)
        {

            SpeciesSetting setting = listBoxSpecies.SelectedItem as SpeciesSetting;
            if (setting != AppConfig.Instance.DefaultSpecie)
            {
                AppConfig.Instance.DefaultSpecieName = setting.Name;
                AppConfig.Instance.DefaultSpecie.Load();
            }
            if (_customAnnotationFile != null)
            {
                AnnotationData.Load(_customAnnotationFile);
            }

            DialogResult = true;
            Close();
        }

        private void buttoCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            listBoxSpecies.ItemsSource = AppConfig.Instance.SpeciesSettings;
            if (ChromePairData.Data == null)
                labelWarning.Visibility = System.Windows.Visibility.Collapsed;
            listBoxSpecies.SelectedItem = AppConfig.Instance.DefaultSpecie;
            textBoxAnnotationFile.IsReadOnly = true;
            textBoxAnnotationFile.IsEnabled = false;
            if (!_showVisiblityChoose)
                checkBoxShow.Visibility = System.Windows.Visibility.Collapsed;
        }

        private void listBoxSpecies_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (null == listBoxSpecies.SelectedItem)
                return;

            SpeciesSetting setting = listBoxSpecies.SelectedItem as SpeciesSetting;
            this.textBoxAnnotationFile.Text = setting.AnnotationFile;

        }
        public bool _showMe = true;
        private void checkBoxShow_Checked(object sender, RoutedEventArgs e)
        {
            bool isChecked =(bool) checkBoxShow.IsChecked;
            _showMe = !isChecked;
        }
    }
}
